#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e3+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL maxx[maxn],minx[maxn],maxy[maxn],miny[maxn];
LL a[maxn][maxn];
char s[maxn][maxn];
LL ans[20];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL T;cin>>T;
  while(T--){
    LL n;cin>>n;
    for(LL i=0;i<n+10;i++) maxx[i]=0,minx[i]=n,maxy[i]=0,miny[i]=n;
    for(LL i=0;i<20;i++) ans[i]=0;
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=n;j++) cin>>s[i][j];
    }
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=n;j++) a[i][j]=(s[i][j]-'0');
    }
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=n;j++){
            LL t=a[i][j];
            maxx[t]=max(maxx[t],i);
            minx[t]=min(minx[t],i);
            maxy[t]=max(maxy[t],j);
            miny[t]=min(miny[t],j);
        }
    }
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=n;j++){
            LL t=a[i][j];
            ans[t]=max(ans[t],abs(maxx[t]-i)*max(n-j,j-1) );
            ans[t]=max(ans[t],abs(i-minx[t])*max(n-j,j-1) );
            ans[t]=max(ans[t],abs(maxy[t]-j)*max(n-i,i-1) );
            ans[t]=max(ans[t],abs(miny[t]-j)*max(n-i,i-1) );
        }
    }
    for(LL i=0;i<10;i++){
        cout<<ans[i]<<" ";
    }
    cout<<"\n";
  }
return 0;
}
